# 所有数据库的初始化程序
import datetime
import json
import string
import time

from fastapi import APIRouter
from re_common.baselibrary.utils.baseencode import BaseEncode
from re_common.baselibrary.utils.basefile import BaseFile
from re_common.baselibrary.utils.basetime import BaseTime
from re_common.baselibrary.utils.core.requests_core import MsgCode

from apps.core.m_route import ContextIncludedRoute
from apps.core.return_info import ReturnInfo, FAILED, SUCCESS
from apps.crawler_platform.core_platform.core_g import SQLTable, CoreSqlValue
from apps.crawler_platform.core_platform.core_sql import CoreSqlMixin

router = APIRouter(route_class=ContextIncludedRoute)


@router.post("/journal/wanfanghome")
async def init_wf_home():
    return_info = ReturnInfo()
    lists = []
    dicts = {
        "home_rawid": "0/",
        "task_name": "wanfangjournal",
        "task_tag": "wanfangclasshome",
        "sub_db_id": "00004",
        "page_index": "0",
        "home_json": "{}",
    }
    dicts1 = {
        "home_rawid": "None",
        "task_name": "wanfangmed",
        "task_tag": "wanfangmedhome",
        "sub_db_id": "00288",
        "page_index": "1",
        "home_json": "{}",
    }
    lists.append(dicts)
    lists.append(dicts1)
    for i in string.digits + string.ascii_uppercase:
        t = dicts.copy()
        t["home_rawid"] = i
        t["task_tag"] = "wanfangqkhome"
        lists.append(t)
    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.journal_home, list_key, list_v,
                                                      insert=CoreSqlValue.replace_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/journal/cnkihome")
async def init_cnki_home():
    return_info = ReturnInfo()
    lists = []
    # 全部期刊 翻页初始化
    dicts = {
        "home_rawid": "None",
        "task_name": "cnkijournal",
        "task_tag": "cnkiqkhomeinit",
        "sub_db_id": "00002",
        "page_index": "1",
        "home_json": "{}",
    }
    # 分类期刊初始化
    dicts1 = {
        "home_rawid": "None",
        "task_name": "cnkijournal",
        "task_tag": "cnkiclasshome",
        "sub_db_id": "00002",
        "page_index": "1",
        "home_json": "{}",
    }
    # 辑刊初始化
    dicts2 = {
        "home_rawid": "None",
        "task_name": "cnkijournal",
        "task_tag": "cnkijclasshome",
        "sub_db_id": "00002",
        "page_index": "1",
        "home_json": "{}",
    }
    dicts3 = {
        "home_rawid": "None",
        "task_name": "cnkicfjd",
        "task_tag": "cnkicfjdhome",
        "sub_db_id": "00169",
        "page_index": "1",
        "home_json": "{}",
    }
    dicts4 = {
        "home_rawid": "None",
        "task_name": "cnkicjfx",
        "task_tag": "cnkicjfxhome",
        "sub_db_id": "00451",
        "page_index": "0",
        "home_json": "{}",
    }
    dicts5 = {
        "home_rawid": "None",
        "task_name": "cnkicjfr",
        "task_tag": "cnkicjfrhome",
        "sub_db_id": "00452",
        "page_index": "1",
        "home_json": '{"parm":"{0}"}',
    }
    lists.append(dicts)
    lists.append(dicts1)
    lists.append(dicts2)
    lists.append(dicts3)
    lists.append(dicts4)
    lists.append(dicts5)

    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.journal_home, list_key, list_v,
                                                      insert=CoreSqlValue.replace_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/journal/chaoxinghome")
async def init_cx_home():
    return_info = ReturnInfo()
    lists = []
    dicts = {
        "home_rawid": "None",
        "task_name": "chaoxingjournal",
        "task_tag": "chaoxinghome",
        "sub_db_id": "00006",
        "page_index": "1",
        "home_json": "{}",
    }
    dicts1 = {
        "home_rawid": "",
        "task_name": "chaoxingjournal",
        "task_tag": "chaoxingqkhomeclass",
        "sub_db_id": "00006",
        "page_index": "1",
        "home_json": "{}",
    }
    lists.append(dicts)
    lists.append(dicts1)
    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.journal_home,
                                                      list_key,
                                                      list_v,
                                                      insert=CoreSqlValue.replace_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/journal/naturehome")
async def init_naturehome_home():
    return_info = ReturnInfo()
    lists = []
    dicts = {
        "home_rawid": "None",
        "task_name": "naturejournal",
        "task_tag": "naturehome",
        "sub_db_id": "00035",
        "page_index": "0",
        "is_active": "1",
        "home_json": "{}",
    }
    lists.append(dicts)
    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.journal_home, list_key, list_v,
                                                      insert=CoreSqlValue.replace_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/other/nstl_list")
async def init_nstl_list_list():
    return_info = ReturnInfo()
    lists = []
    time = int(BaseTime().get_time() * 1000)
    tid = BaseEncode.get_md5_value(str(time) + 'istic2009nstlweb')
    home_dicts = {
        "time": time,
        "tid": tid
    }
    dicts = {
        "list_rawid": "None",
        "task_name": "nstl",
        "task_tag": "nstllist",
        "sub_db_id": "",
        "page_index": "1",
        "is_active": "1",
        "list_json": json.dumps(home_dicts, ensure_ascii=False),
    }

    lists.append(dicts)
    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_list, list_key, list_v,
                                                      insert=CoreSqlValue.replace_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/other/cnkilaw_list")
async def init_cnkilaw_list():
    return_info = ReturnInfo()
    lists = []
    dicts = {
        "list_rawid": "None",
        "task_name": "cnkilaw",
        "task_tag": "cnkilawlist",
        "sub_db_id": "",
        "page_index": "1",
        "is_active": "1"
    }

    lists.append(dicts)
    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_list, list_key, list_v,
                                                      insert=CoreSqlValue.replace_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


def getDateList(start_date, end_date):
    date_list = []
    start_date = datetime.datetime.strptime(start_date, '%Y-%m-%d')
    end_date = datetime.datetime.strptime(end_date, '%Y-%m-%d')
    date_list.append(start_date.strftime('%Y-%m-%d'))
    while start_date < end_date:
        start_date += datetime.timedelta(days=1)
        date_list.append(start_date.strftime('%Y-%m-%d'))
    return date_list


@router.post("/other/cnkizl_home")
async def init_cnkizl_home():
    now_date = time.strftime('%Y-%m-%d', time.localtime())
    return_info = ReturnInfo()
    # list_key = ["list_rawid", "task_name", "task_tag", "sub_db_id","home_json", "page_index","state","is_active"]
    list_key = ["list_rawid", "task_name", "task_tag", "sub_db_id", "home_json", "page_index", "is_active"]
    list_v = []
    list_tag = ["SCPD_FM", "SCPD_WG", "SCPD_XX"]
    tagDict = {
        "SCPD_FM": "发明专利",
        "SCPD_WG": "外观设计",
        "SCPD_XX": "实用新型",
    }
    # date_list = getDateList("1985-01-01", "2021-12-31")
    # date_list = getDateList("2022-01-01", now_date)
    date_list = getDateList("1985-01-01", now_date)
    for tag in list_tag:
        for dt in date_list:
            home_json = {"types": tag, "types_cn": tagDict[tag], "start_date": dt}
            # list_v.append(("{},{}".format(tag, dt), "cnkipatent", "cnkizlhome", "00003",json.dumps(home_json, ensure_ascii=False), "-1","5","1"))
            list_v.append(("{},{}".format(tag, dt), "cnkipatent", "cnkizlhome", "00003",
                           json.dumps(home_json, ensure_ascii=False), "-1", "1"))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_home, list_key, list_v,
                                                      insert=CoreSqlValue.insert_ig_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/other/isticword_home")
async def init_cnkizl_home():
    now_date = time.strftime('%Y-%m-%d', time.localtime())
    return_info = ReturnInfo()
    list_key = ["list_rawid", "task_name", "task_tag", "sub_db_id", "home_json", "page_index", "is_active"]
    list_v = []
    list_v.append(("None", "isticword", "isticword_home", "",
                   json.dumps({}, ensure_ascii=False), "-1", "1"))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_home, list_key, list_v,
                                                      insert=CoreSqlValue.insert_ig_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/other/cnkipaper_class")
async def init_cnkipaper_class():
    return_info = ReturnInfo()
    lists = []
    # 报纸
    dicts = {
        "list_rawid": "0001",
        "task_name": "cnkiccndpaper",
        "task_tag": "cnkipaperclass",
        "sub_db_id": "00080",
        "page_index": "1",
        "home_json": json.dumps({"level": "中央级", "val": "0001"}, ensure_ascii=False),
    }
    dicts1 = {
        "list_rawid": "0002",
        "task_name": "cnkiccndpaper",
        "task_tag": "cnkipaperclass",
        "sub_db_id": "00080",
        "page_index": "1",
        "home_json": json.dumps({"level": "地方级", "val": "0002"}, ensure_ascii=False),
    }
    lists.append(dicts)
    lists.append(dicts1)
    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_home, list_key, list_v,
                                                      insert=CoreSqlValue.replace_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/other/cnki_image_home")
async def cnki_image_home_class():
    return_info = ReturnInfo()
    lists = []
    # 报纸
    dicts = {
        "list_rawid": "None",
        "task_name": "cnkiimage",
        "task_tag": "cnkiimagehome",
        "sub_db_id": "",
        "page_index": "1",
        "home_json": json.dumps({}, ensure_ascii=False),
    }
    lists.append(dicts)

    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_home, list_key, list_v,
                                                      insert=CoreSqlValue.replace_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/other/cnkithesis_class")
async def init_cnkithesis_class():
    return_info = ReturnInfo()
    lists = []
    # 硕士论文
    dicts = {
        "list_rawid": "0001",
        "task_name": "cnkithesis",
        "task_tag": "cnkithesisclass",
        "sub_db_id": "00075",
        "page_index": "1",
        "home_json": "{}",
    }
    lists.append(dicts)
    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_home, list_key, list_v,
                                                      insert=CoreSqlValue.replace_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/other/cnkicdfdthesis_class")
async def init_cnkicdfdthesis_class():
    return_info = ReturnInfo()
    lists = []
    # 博士论文
    dicts = {
        "list_rawid": "0001",
        "task_name": "cnkicdfdthesis",
        "task_tag": "cnkicdfdthesisclass",
        "sub_db_id": "00310",
        "page_index": "1",
        "home_json": "{}",
    }
    lists.append(dicts)
    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_home, list_key, list_v,
                                                      insert=CoreSqlValue.replace_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/other/cnkiconference_class")
async def init_cnkiconference_class():
    return_info = ReturnInfo()
    lists = []
    # 硕士论文
    dicts = {
        "list_rawid": "0001",
        "task_name": "cnkiconference",
        "task_tag": "cnkiconferenceclass",
        "sub_db_id": "00090",
        "page_index": "1",
        "home_json": "{}",
    }
    lists.append(dicts)
    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_home, list_key, list_v,
                                                      insert=CoreSqlValue.replace_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/other/cnkiipfdconference_class")
async def init_cnkiipfdconference_class():
    return_info = ReturnInfo()
    lists = []
    dicts = {
        "list_rawid": "0001",
        "task_name": "cnkiipfdconference",
        "task_tag": "cnkiipfdconferenceclass",
        "sub_db_id": "00091",
        "page_index": "1",
        "home_json": "{}",
    }
    lists.append(dicts)
    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_home, list_key, list_v,
                                                      insert=CoreSqlValue.replace_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/other/wanfangthesis_class")
async def init_wanfangthesis_class():
    return_info = ReturnInfo()
    lists = []
    dicts = {
        "list_rawid": "0001",
        "task_name": "wanfangthesis",
        "task_tag": "wanfangthesis_class",
        "sub_db_id": "00005",
        "page_index": "1",
        "home_json": "{}",
    }
    lists.append(dicts)
    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_home, list_key, list_v,
                                                      insert=CoreSqlValue.replace_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/other/wanfangconference_class")
async def init_wanfangconference_class():
    now_year = time.strftime('%Y', time.localtime())
    return_info = ReturnInfo()
    list_tag = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
                'v', 'w', 'x', 'y', 'z']
    lists = []
    for name in list_tag:
        for years in range(1990, int(now_year) + 1):
            home_json = {
                "tag": name.upper(),
                "years": years
            }
            lists.append({
                "list_rawid": "{}_{}".format(name.upper(), years),
                "task_name": "wanfangconference",
                "task_tag": "wanfangconference_class",
                "sub_db_id": "00105",
                "page_index": "0",
                "home_json": json.dumps(home_json, ensure_ascii=False),
            })
    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_home, list_key, list_v,
                                                      insert=CoreSqlValue.insert_ig_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/other/wanfangunconference_class")
async def init_wanfangunconference_class():
    now_year = time.strftime('%Y', time.localtime())
    return_info = ReturnInfo()
    list_tag = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
                'v', 'w', 'x', 'y', 'z']
    lists = []
    for name in list_tag:
        for years in range(1990, int(now_year) + 1):
            home_json = {
                "tag": name.upper(),
                "years": years
            }
            lists.append({
                "list_rawid": "{}_{}".format(name.upper(), years),
                "task_name": "wanfangunconference",
                "task_tag": "wanfangunconference_class",
                "sub_db_id": "00411",
                "page_index": "0",
                "home_json": json.dumps(home_json, ensure_ascii=False),
            })
    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_home, list_key, list_v,
                                                      insert=CoreSqlValue.insert_ig_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/other/_wanfangpatent_class")
async def init_wanfangzl_home():
    now_date = time.strftime('%Y-%m-%d', time.localtime())
    return_info = ReturnInfo()
    date_list = getDateList("1985-01-01", now_date)
    lists = []
    for pubdate in date_list:
        list_json = {}
        list_json["search_id"] = pubdate
        list_json["search_name"] = pubdate
        list_json["pub_date"] = pubdate
        list_json["facetField"] = "MainClassCodeForSearch"
        lists.append({
            "task_name": "wanfangpatent",
            "task_tag": "wanfangpatent_search_list",
            "sub_db_id": "00052",
            "list_rawid": pubdate,
            "page": 1,
            "page_index": "1",
            "list_json": json.dumps(list_json, ensure_ascii=False)
        })
    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_list, list_key, list_v,
                                                      insert=CoreSqlValue.insert_ig_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/other/bookanjournal_init")
async def init_bookanjournal():
    return_info = ReturnInfo()
    lists = []
    dicts = {
        "home_rawid": "None",
        "task_name": "bookanjournal",
        "task_tag": "bookanjournalinit",
        "sub_db_id": "",
        "page_index": "1",
        "home_json": "{}",
    }
    lists.append(dicts)
    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.journal_home, list_key, list_v,
                                                      insert=CoreSqlValue.replace_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/other/baiduxueshu_home")
async def init_baiduxueshu_home():
    return_info = ReturnInfo()
    lists = []
    dicts = {
        "task_name": "baiduxueshu",
        "task_tag": "baiduxuehome",
        "home_json": "{}",
        "other_dicts": "{}",
        "null_dicts": "{}"
    }
    for i in BaseFile.read_file_r_mode_yield(r"F:\data\baiduxueshu\大于等于20.txt"):
        i = i.split("	")[0]
        t = dicts.copy()
        t["list_rawid"] = i
        lists.append(t)
        if len(lists) > 10000:
            list_v = []
            list_key = list(lists[0].keys())
            for item in lists:
                list_v.append(tuple(item.values()))
            bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_home, list_key, list_v,
                                                              insert=CoreSqlValue.replace_it)
            if not bools:
                return_info.status = FAILED
                return_info.msg_code = MsgCode.SQL_INSERT_ERROR
                return_info.msg = "insert_many_sql 出现错误"
            lists.clear()

    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_home, list_key, list_v,
                                                      insert=CoreSqlValue.replace_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()


@router.post("/other/samropenstdstandard_list_init")
async def init_samropenstdstandard():
    return_info = ReturnInfo()
    lists = []
    dicts1 = {
        "task_name": "samropenstdstandard",
        "task_tag": "samropenstdstandard_list",
        'list_rawid': '/bzgk/gb/std_list_type?pageSize=50&p.p1=1&p.p90=circulation_date&p.p91=desc',
        'list_json': '{"std_type":"强制性国家标准"}',
        "sub_db_id": "00668",
        "page_index": "1",
    }
    dicts2 = {
        "task_name": "samropenstdstandard",
        "task_tag": "samropenstdstandard_list",
        'list_rawid': '/bzgk/gb/std_list_type?pageSize=50&p.p1=2&p.p90=circulation_date&p.p91=desc',
        'list_json': '{"std_type":"推荐性国家标准"}',
        "sub_db_id": "00668",
        "page_index": "1",
    }
    dicts3 = {
        "task_name": "samropenstdstandard",
        "task_tag": "samropenstdstandard_list",
        'list_rawid': '/bzgk/gb/std_list_type?pageSize=50&p.p1=3&p.p90=circulation_date&p.p91=desc',
        'list_json': '{"std_type":"指导性技术文件"}',
        "sub_db_id": "00668",
        "page_index": "1",
    }
    lists.append(dicts1)
    lists.append(dicts2)
    lists.append(dicts3)
    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_list, list_key, list_v,
                                                      insert=CoreSqlValue.replace_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()

@router.post("/other/nstrsreport_list_init")
async def init_nstrsreport():
    return_info = ReturnInfo()
    lists = []
    dicts1 = {
        "task_name": "nstrsreport",
        "task_tag": "nstrsreport_list",
        'list_rawid': '/rest/kjbg/wfKjbg/list',
        'list_json': '{}',
        "sub_db_id": "00669",
        "page_index": "1",
    }
    lists.append(dicts1)
    list_v = []
    list_key = list(lists[0].keys())
    for item in lists:
        list_v.append(tuple(item.values()))
    bools, dicts = await CoreSqlMixin.insert_many_sql(SQLTable.other_list, list_key, list_v,
                                                      insert=CoreSqlValue.replace_it)
    if not bools:
        return_info.status = FAILED
        return_info.msg_code = MsgCode.SQL_INSERT_ERROR
        return_info.msg = "insert_many_sql 出现错误"
    else:
        return_info.status = SUCCESS
        return_info.msg_code = MsgCode.SUCCESS_CODE
        return_info.msg = "insert_many_sql 初始化成功"
    return return_info.todict()